package club.janna.netty.buf;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

public class BufDemo {
    public static void main(String[] args) {
//        ByteBuf byteBuf = Unpooled.directBuffer(10);
        ByteBuf byteBuf = Unpooled.buffer(10);

        System.out.println("buf -> " + byteBuf);
        byte[] bytes = {1, 2, 3, 4, 5};
        byteBuf.writeBytes(bytes);
        System.out.println("buf -> " + byteBuf);

        byte b1 = byteBuf.readByte();
        byte b2 = byteBuf.readByte();
        System.out.println("b1 -> " + b1);
        System.out.println("b2 -> " + b2);
        System.out.println("buf -> " + byteBuf);

        System.out.println("buf.discard");
        byteBuf.discardReadBytes();
        System.out.println("buf -> " + byteBuf);
        byteBuf.writeByte(6);
        System.out.println("buf -> " + byteBuf);

        System.out.println("buf.clear");
        byteBuf.clear();
        System.out.println("buf -> " + byteBuf);

        byte[] bytes1 = {1,1,1,1,1,1,1,1,1,1,1,1,1};
        byteBuf.writeBytes(bytes1);
        System.out.println("buf -> " + byteBuf);

        byteBuf.release();
    }
}
